using AOT;
using Unity.Burst;

namespace DA.AnimGraph {
    [BurstCompile]
    public unsafe partial struct SyncGroupPerk {
        public struct SetupData {
            public AUID groupID;
        }

        AUID groupID;
        int enterEvaluateCounter;

        [BurstCompile]
        static void SetupLink(SyncGroupPerk* self, PerkLink* link) {
            link->SetupPerk(self);
        }

        void Setup(in SetupData setupData) {
            groupID = setupData.groupID;
        }

        [BurstCompile]
        [MonoPInvokeCallback(typeof(PerkLink.EvaluateDelegate))]
        private static void Evaluate(in void* ptr, in TimeState* timeState, bool onEnter, in EvaluateContext evaluateContext, in GraphContext graphContext, ref UpstreamData upstream, ref ScopeContext scope) {
            if (timeState != null) {
                var self = (SyncGroupPerk*)ptr;

                if (onEnter) {
                    self->enterEvaluateCounter = evaluateContext.evaluateCounter;
                }

                upstream.AddSyncClip(self->groupID, new SyncClipInfo() {
                    timeState = timeState,
                    enterEvaluateCounter = self->enterEvaluateCounter
                });
            }
        }
    }
}
